#
# This file is a part of the open-eBackup project.
# This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
# If a copy of the MPL was not distributed with this file, You can obtain one at
# http://mozilla.org/MPL/2.0/.
#
# Copyright (c) [2024] Huawei Technologies Co.,Ltd.
#
# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
# EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
# MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
#

from informix.comm.const import AllStepEnum
from informix.job_manager import JobManager
from informix.param.connect_param_parse import ConnectParam
from informix.param.resource_param_parse import ResourceParam
from informix.service.BaseService import MetaService, SupportResourceInterfaceMixin, CheckApplicationInterfaceMixin, \
    RemoveProtectInterfaceMixin
from informix.service.resource.resource_output import Resource


class ResourceService(MetaService):
    def __init__(self, job_manager, param_dict):
        super().__init__(job_manager, param_dict)
        self.param = self.gen_param_obj()
        self.resource_manager = Resource(self.job_manager, self.param)

    def gen_param_obj(self):
        param = ResourceParam(self.param_dict)
        return param

    def get_steps(self):
        pass


@JobManager.register(AllStepEnum.SUPPORT_RESOURCE)
class SupportResource(ResourceService, SupportResourceInterfaceMixin):
    def __init__(self, job_manager, param_dict):
        super().__init__(job_manager, param_dict)

    def get_steps(self):
        steps = [self.resource_manager.support_informix_resource]
        return steps


class ConnectService(MetaService):
    def __init__(self, job_manager, param_dict):
        super().__init__(job_manager, param_dict)
        self.param = self.gen_param_obj()
        self.resource_manager = Resource(self.job_manager, self.param)

    def gen_param_obj(self):
        param = ConnectParam(self.param_dict)
        return param

    def get_steps(self):
        pass


@JobManager.register(AllStepEnum.CHECK_APPLICATION)
class CheckApplicationService(ConnectService, CheckApplicationInterfaceMixin):
    def __init__(self, job_manager, param_dict):
        super().__init__(job_manager, param_dict)

    def get_steps(self):
        steps = [self.resource_manager.check_application]
        return steps


@JobManager.register(AllStepEnum.REMOVE_PROTECT)
class RemoveProtectService(ConnectService, RemoveProtectInterfaceMixin):
    def __init__(self, job_manager, param_dict):
        super().__init__(job_manager, param_dict)

    def get_steps(self):
        steps = [self.resource_manager.remove_protect]
        return steps